4 extension CVImageBuffer {
6 private static let contextQueue = DispatchQueue(label: "com.example.contextQueue")
7 static let sharedContext: CIContext = {
11 var cgImage: CGImage? {
13 CVImageBuffer.contextQueue.sync {
14 let ciImage = CIImage(cvImageBuffer: self)
15 let width = CVPixelBufferGetWidth(self)
16 let height = CVPixelBufferGetHeight(self)
17 result = CVImageBuffer.sharedContext.createCGImage(ciImage, from: CGRect(x: 0, y: 0, width: width, height: height))